package app.scraper.textyard;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.impl.client.AbstractHttpClient;

import com.gargoylesoftware.htmlunit.HttpWebConnection;
import com.gargoylesoftware.htmlunit.WebClient;

public class RetryHttpWebConnection extends HttpWebConnection {

	private static final int MAX_RETRIES = 2;

	public RetryHttpWebConnection(final WebClient webClient) {
		super(webClient);
	}

	@Override
	protected AbstractHttpClient createHttpClient() {
		AbstractHttpClient httpClient = super.createHttpClient();
		httpClient.getParams()
				.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(MAX_RETRIES, false));
		return httpClient;
	}
}
